package com.example.binke.controller;


import com.example.binke.mapper.OrderMapper;
import com.example.binke.pojo.Order;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

@RestController
public class OrderController {



    @Autowired(required = false)
    private OrderMapper orderMapper;


    //-http://localhost:8080/getUser?id=1
    @RequestMapping(value="/getOrder",method = RequestMethod.GET)
    public Order getOrder(@RequestParam("id") Integer id) {
        Order order=orderMapper.getOne(id);
        return order;
    }

    @RequestMapping(value="/getOrders",method = RequestMethod.GET)
    public List<Order> getOrders() {
        return orderMapper.getAll();
    }

    //-http://localhost:8080/add?name=abc&passwd=123&appid=95955542783
    @RequestMapping(value = "/add", method = RequestMethod.GET)
    public void save(@RequestParam("id") int id,
                     @RequestParam("customerId") int customerId,
                     @RequestParam("date") Date date,
                     @RequestParam("address") String address,
                     @RequestParam("state") String state,
                     @RequestParam("total") int total){
        orderMapper.insert(new Order(id,customerId,date,address,state,total));
    }


    @RequestMapping(value = "/delete/{id}", method = RequestMethod.GET)
    public void delete(@PathVariable("id") Integer id) {
        orderMapper.delete(id);

    }


}
